package net.zwet.clanworks.connectors.eve.api.connector;

import java.io.InputStream;

import net.zwet.clanworks.connectors.eve.api.exceptions.EveConnectionException;
import net.zwet.clanworks.connectors.eve.api.exceptions.EveAuthenticationException;
import net.zwet.clanworks.connectors.eve.api.connector.url.Parameters;
import net.zwet.clanworks.connectors.eve.api.connector.url.Urls;

public class EveApiConnector extends ConnectorBase {
	
	// --------------------------------------------------------------------------------------[ Constructors ]-----

	public EveApiConnector() {
		super();
	}
	
	public EveApiConnector(String keyID, String vCode) {
		super(keyID, vCode);
	}

	// --------------------------------------------------------------------------------------[ Public methods ]-----

	/**
	 * This method will retrieve the characters in an EveService XML for the set
	 * authentication and converts the result to the Characters object before
	 * returning it
	 *
	 * @return
	 * @throws EveConnectionException
	 */
	public final InputStream getCharacters ( String keyID, String vCode ) throws EveConnectionException {
		Parameters parameters = new Parameters( keyID, vCode ) ;
		return connect ( Urls.CHARACTERS, parameters );
	}
	
	/**
	 * This method will retrieve the characters in an EveService XML for the set
	 * authentication and converts the result to the Characters object before
	 * returning it
	 * 
	 * @return
	 * @throws EveConnectionException
	 * @throws EveAuthenticationException
	 */
	public final InputStream getCharacters() throws EveConnectionException, EveAuthenticationException {
		// make sure the 'generic' parameters (userId, ApiKey) are provided.
		if ( ! this.userID.isEmpty() && ! this.apiKey.isEmpty() ) {
			return this.getCharacters( this.userID, this.apiKey );
		} else {
			String message ="Missing userID [" + this.userID + "] and/or apiKey [" + this.apiKey + "]";
			log.error(message);
			throw new EveAuthenticationException(message);
		}
	}	
	
	/**
	 * This method will retrieve the sheet for a certain character in an EveService XML
	 * for the provided characterId and converts the result to the CharacterSheet 
	 * instance before returning it
	 * 
	 * @return
	 */
	public final InputStream getCharacterSheet(String characterID) throws EveConnectionException {
		Parameters parameters = new Parameters( this.userID, this.apiKey );
		parameters.addParameter("characterID", characterID);

		return connect(Urls.CHARACTER_SHEET, parameters);
	}

	public final InputStream getSkillQueue(String characterID) throws EveConnectionException {
		Parameters parameters = new Parameters( this.userID, this.apiKey );
		parameters.addParameter("characterID", characterID);

		return connect(Urls.SKILL_QUEUE, parameters);
	}

	public final InputStream getServerStatus() throws EveConnectionException {
		return connect(Urls.SERVER_STATUS);
	}

	public final InputStream getSkillTree( ) throws EveConnectionException {
		return connect(Urls.SKILL_TREE);
	}


	/**
	 * 
	 */
	public final void getCorporationSheet() {

	}

	public final void getMedals() {

	}

	public final void getCorporationMedals() {

	}

	public final void getCorporationMemberMedals() {

	}

	public final void getCharacterPortrait() throws EveConnectionException {

	}
}
